package cn.faster;

import org.junit.jupiter.api.Test;

/**
 * @author xiaoCoder
 * @version 1.0
 * @description:
 * @date 2021/8/10 18:33
 */
public class BuilderDemo {
    private String name;
    private Integer age;

    public String getName() {
        return name;
    }

    public Integer getAge() {
        return age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    static class BuilderDemoBuild {
        private String name;
        private Integer age;

        public String getName() {
            return name;
        }

        public BuilderDemoBuild setName(String name) {
            this.name = name;
            return this;
        }

        public Integer getAge() {
            return age;
        }

        public BuilderDemoBuild setAge(Integer age) {
            this.age = age;
            return this;
        }

        public BuilderDemo build() {
            BuilderDemo builderDemo = new BuilderDemo();
            builderDemo.setAge(this.getAge());
            builderDemo.setName(this.getName());
            return builderDemo;
        }

    }

    public BuilderDemoBuild builder() {
        return new BuilderDemoBuild();
    }

    @Override
    public String toString() {
        return "BuilderDemo{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Test
    public void demo(){
        BuilderDemo builderDemo = new BuilderDemo();
        BuilderDemo build = builderDemo
                .builder()
                .setAge(1)
                .setName("123")
                .build();
        System.out.println(build);
    }

}



